import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((err) => err)
}
const routerReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(location) {
  return routerReplace.call(this, location).catch((err) => err)
}

/**
meta: {
  requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
}
**/
const routes = [{
    path: '/',
    redirect: '/login',
    meta: {
      requireAuth: true
    }
  },
  {
    path: '/login',
    meta: {
      requireAuth: true
    },
    component: () =>
      import ('@/views/login/login')
  },
  {
    path: '/bashboard/bashboard',
    meta: {
      requireAuth: false
    },
    component: () =>
      import ('@/views/bashboard/Index')
  },
  {
    path: '/home',
    meta: {
      requireAuth: true
    },
    component: () =>
      import ('@/views/home/home'),
    children: [{
        path: '/home',
        meta: {
          requireAuth: true
        },
        redirect: '/home/data_search'
      },
      {
        path: '/home/cart_manage',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/operate/cart_manage/cart_manage.vue')
      },
      {
        path: '/home/site_manage',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/operate/site_manage/site_manage.vue')
      },
      {
        path: '/home/parameter_configure',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/operate/parameter_configure/parameter_configure.vue')
      },
      {
        path: '/home/user_manage',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/operate/user_manage/user_manage.vue')
      },
      {
        path: '/home/role_manage',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/operate/role_manage/role_manage.vue')
      },
      {
        path: '/home/source_management',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/manage/source_management')
      },
      {
        path: '/home/early_warning',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/monitor/early_warning/early_warning.vue')
      },
      {
        path: '/home/data_search',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/monitor/data_search/data_search.vue')
      },
      // {
      //   path: '/home/data_search/detail',
      //   meta: {
      //     requireAuth: true
      //   },
      //   component: () => import('@/views/monitor/data_search/cpns/data_search_detail.vue')
      // },
      {
        path: '/home/equipment_monitoring',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/monitor/equipment_monitoring/equipment_monitoring.vue')
      },
      {
        path: '/home/equipment_management',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/monitor/equipment_management/equipment_management.vue')
      },
      {
        path: '/home/video_surveillance',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('@/views/monitor/video_surveillance/video_surveillance.vue')
      },
      {
        path: '/home/census',
        meta: {
          requireAuth: true
        },
        component: () =>
          import ('../views/census/Index')
      }
    ]
  }
  // {
  //   path: '/map',
  //   component: () => import('@/components/map/map.vue')
  // }
]

const router = new VueRouter({
  mode: 'hash',
  // base: process.env.BASE_URL,
  routes
})

export default router